/*
 * @Description: 用户的路由
 * @Version: 2.0
 * @Autor: 黄康辉
 * @Date: 2021-11-17 17:32:22
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2022-01-11 19:14:09
 */
const {
  getUserInfoController,
  registerInfoController,
  loginController,
  upDateUserController,
  delUserController,
  getAllUserController
} = require('../controller/userController')
// const axios = require('axios')
const result = require('../utils/result')
const getUserApi = (router) => {
  router.get('/userAA', async (ctx) => {
    ctx.body = {
      data: 'asdasda'
    }
  })
  // 主题色
  router.post('/theme', async (ctx) => {
    const data = ctx.request.body
    console.log(data, 'data')
    // const res = await axios({
    //   method: 'POST',
    //   url: 'https://element-api.ele.me/element/theme/updateVariable?version=2.15.7',
    //   data
    // })
    ctx.body = result('0', { data: `#custom` })
  })

  router.get('/userInfo', async (ctx) => {
    const token = ctx.headers.authorization
    const result = await getUserInfoController(token)
    ctx.body = result
  })
  router.post('/register', async (ctx) => {
    const result = await registerInfoController(ctx.request.body)
    ctx.body = result
  })
  router.post('/login', async (ctx) => {
    const { userName, passWord } = ctx.request.body
    const result = await loginController({ userName, passWord })
    ctx.body = result
  })
  router.post('/upDateUser', async (ctx) => {
    const result = await upDateUserController(ctx.request.body)
    ctx.body = result
  })
  router.post('/delUser', async (ctx) => {
    const result = await delUserController(ctx.request.body)
    ctx.body = result
  })

  router.get('/getAllUser', async (ctx) => {
    const result = await getAllUserController()
    ctx.body = result
  })
}
module.exports = getUserApi
